var vue = new Vue({
	el : '#index_body',
	data : {
		maxp : 0,
		items1 : [], //第一行,每行四个
		items2 : [], //第二行,每行四个
		items3 : [], //第三行,每行四个
		items4 : [], //第四行,每行四个
		prebtnLoading : false, //按钮的状态
		nexbtnLoading : false
	},
	mounted(){
		//页面加载完即可执行
		this.init(1);
	},
	methods : {
		init : function(page){
			$.ajax({
				url : COMMON_URL.URL+'getAllAdvert',
				data : {page : page},
				dataType : 'json',
				type : 'get',
				success : function(data){
					debugger;
					if(data.ok){
						var value = data.attrs;
						vue.items1 = value[0];
						vue.items2 = value[1];
						vue.items3 = value[2];
						vue.items4 = value[3];
						vue.maxp = value['maxPage'];
						$('#page_').text(data.data);
					}else{
						swal(data.msg,'','error');
					}
					vue.prebtnLoading = false;
					vue.nexbtnLoading = false;
				},
				error : function(data){
					vue.prebtnLoading = false;
					vue.nexbtnLoading = false;
					swal('查询失败','','error');
				}
				
			});
		},
		gotoDetail:function(val){
			return COMMON_URL.MAINMENU+val;
		},
		prev : function(){
			vue.prebtnLoading = true;
			var currentPage = parseInt($('#page_').text());
			
			if (currentPage == 1) {
				vue.prebtnLoading = false;
				swal('已经是第一页啦','','warning')
				return;
			}
			
			this.init(currentPage-1);
		},
		next : function(){
			this.nexbtnLoading = true;
			var currentPage = parseInt($('#page_').text());
			if (currentPage >= this.maxp) {
				vue.nexbtnLoading = false;
				swal('没有更多数据啦','','warning')
				return;
			}
			
			this.init(currentPage+1);
		}
		
	}
	
});